home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-05-06 | 5.2 KB | 259 lines | [TEXT/MACA] |
- ( *** menu definition procedures. J.L. April 1987 *** )
-
- ONLY FORTH ALSO ASSEMBLER ALSO MAC
-
- HEX
- 4D444546 CONSTANT "mdef
- 0 CONSTANT mDrawMsg
- 1 CONSTANT mChooseMsg
- 2 CONSTANT mSizeMsg
- DECIMAL
-
- CODE white
- MOVE.L (A5),-(A6)
- SUBQ.L #8,(A6)
- RTS
- END-CODE MACH
-
- CODE black
- MOVE.L (A5),-(A6)
- SUBI.L #16,(A6)
- RTS
- END-CODE MACH
-
- CODE gray
- MOVE.L (A5),-(A6)
- SUBI.L #24,(A6)
- RTS
- END-CODE MACH
-
- CODE ltgray
- MOVE.L (A5),-(A6)
- SUBI.L #32,(A6)
- RTS
- END-CODE MACH
-
- CODE dkgray
- MOVE.L (A5),-(A6)
- SUBI.L #40,(A6)
- RTS
- END-CODE MACH
-
- CODE w*
- MOVE.L (A6)+,D1
- MOVE.L (A6)+,D0
- MULS.W D1,D0
- MOVE.L D0,-(A6)
- RTS
- END-CODE MACH
-
- CODE w/
- MOVE.L (A6)+,D1
- MOVE.L (A6)+,D0
- DIVS.W D1,D0
- EXT.L D0
- MOVE.L D0,-(A6)
- RTS
- END-CODE MACH
-
- CODE w/mod
- MOVE.L (A6)+,D1
- MOVE.L (A6)+,D0
- DIVS.W D1,D0
- MOVE.L D0,D1
- SWAP.W D1
- EXT.L D1
- EXT.L D0
- MOVE.L D1,-(A6)
- MOVE.L D0,-(A6)
- RTS
- END-CODE MACH
-
- ( *** menu record data structure *** )
- 0 CONSTANT menuID ( integer )
- 2 CONSTANT menuWidth ( integer )
- 4 CONSTANT menuHeight ( integer )
- 6 CONSTANT menuProc ( handle )
- 10 CONSTANT enableFlags ( longint )
- 14 CONSTANT menuData ( Str255 and other data )
- ( *** menu Data format *** )
- ( counted string: menu title )
- ( followed by 1 to 31 times: )
- ( counted string: menu item )
- ( byte: item icon # )
- ( byte: equivalent character )
- ( byte: check mark character )
- ( byte: text attributes )
- ( .... )
- ( end: zero byte. )
-
- : list.menus
- 32767 0 do
- i call getMhandle
- ?dup IF ." Menu # " i . ." , handle " dup . cr
- ." MenuData:" cr
- @ menuData + dup count type cr ( type menu title )
- dup c@ + 1+ ( start of first item string )
- BEGIN
- dup count dup
- WHILE type cr
- dup c@ + 5 +
- REPEAT drop
- THEN
- PAUSE loop
- ;
-
- ( *** code moved to custom menu routine space starts here *** )
-
- header start
- JMP start ( to be filled later )
- header temprect 8 allot
- header itemrect 8 allot
-
- : * w* ;
- : / w/ ;
- : /mod w/mod ;
-
- : mdef { message theMenu menuRect hitPt whichItem |
- width height wd ht top left item# wi# -- }
- theMenu @ dup menuwidth + w@ -> width
- width 4 / -> wd
- menuheight + w@ -> height
- height 4 / -> ht
- menuRect w@ -> top
- menuRect 2+ w@ -> left
-
- message CASE
- mDrawMsg OF
- height 0 DO
- 4 0 DO
- ['] temprect left i wd * + top j + over wd + over ht +
- call setrect
- ['] tempRect 4 4
- i CASE 0 OF white ENDOF
- 1 OF ltgray ENDOF
- 2 OF gray ENDOF
- 3 OF dkgray ENDOF
- black
- ENDCASE CALL FillRoundRect
- ['] tempRect 4 4 CALL FrameRoundRect
- LOOP
- ht +LOOP
- ENDOF
-
- mChooseMsg OF
- whichItem w@ -> wi#
- ['] ItemRect wi# 1- 4 /mod ht * top + swap wd * left + swap
- over wd + over ht + call setrect
- hitPt menuRect call PtInrect
- IF
- 4 0 DO
- 4 0 DO
- i j 4 * + 1+ -> item#
- ['] temprect left i wd * + top j ht * + over wd + over ht +
- call setrect
- hitPt ['] tempRect call PtInRect
- IF item# wi# <>
- IF ['] ItemRect 4 4 call InvertRoundRect
- ['] tempRect 4 4 call InvertRoundRect
- item# whichItem w!
- THEN
- THEN
- LOOP
- LOOP
- ELSE
- wi# IF ['] ItemRect 4 4 call InvertRoundRect THEN
- 0 whichItem w!
- THEN
- ENDOF
-
- mSizeMsg OF
- 100 theMenu @ menuWidth + w!
- 100 theMenu @ menuHeight + w!
- ENDOF
- ENDCASE
- ;
-
- ( *** glue routine *** )
-
- CODE custom.menu
- LINK A6,#-512 ( 512 bytes of local Forth stack )
- MOVEM.L A0-A5/D0-D7,-(A7) ( save registers )
- MOVE.L A6,A3 ( setup local loop return stack )
- SUBA.L #256,A3 ( in the low 256 local stack bytes )
- MOVE.L 8(A6),D0 ( VAR whichItem: INTEGER )
- MOVE.L 12(A6),D1 ( hitPt: Point )
- MOVE.L 16(A6),A0 ( VAR menuRect: Rect )
- MOVE.L 20(A6),A1 ( theMenu: MenuHandle )
- MOVEQ.L #0,D2
- MOVE.W 24(A6),D2 ( message: INTEGER )
-
- MOVE.L D2,-(A6)
- MOVE.L A1,-(A6)
- MOVE.L A0,-(A6)
- MOVE.L D1,-(A6)
- MOVE.L D0,-(A6)
-
- JSR mdef ( call Forth routine )
-
- MOVEM.L (A7)+,A0-A5/D0-D7 ( restore registers )
- UNLK A6
- MOVE.L (A7)+,A0 ( return address )
- ADD.W #18,A7 ( pop off 18 bytes of parameters )
- JMP (A0)
- END-CODE
-
- header end
-
- ' custom.menu ' start 2+ - ' start 2+ w!
-
- ( *** installation *** )
- variable Hregular
-
- : install.custom { menu# | mh procH -- }
- menu# call getMHandle -> mh
- mh 0= abort" Non-existing menu ID given."
- ['] start ['] end over - call PtrToHand
- abort" Can't get enough memory to install."
- -> procH
- mh call HLock
- mh @ menuProc + @ Hregular !
- procH mh @ menuProc + !
- mh call HUnLock
- . . cr
- ;
-
- : remove.custom { menu# | mh procH -- }
- menu# call getMHandle -> mh
- mh 0= abort" Non-existing menu ID given."
- mh call HLock
- mh @ menuProc + @ call DisposHandle
- Hregular @ mh @ menuProc + !
- mh call HUnLock
- . . . cr
- ;
-
- ( *** making a resource *** )
- : $create-res call CreateResFile call ResError L_ext ;
-
- : $open-res { addr | refNum -- result }
- addr call openresfile -> refNum
- call ResError L_ext
- dup not IF drop refNum THEN
- ;
-
- : $close-res call CloseResFile call ResError L_ext ;
-
- : make-mdef { | refNum -- }
- " mdef.res" dup $create-res
- abort" You have to delete the old 'mdef.res' file first."
- $open-res dup -> refNum call UseResFile
- ['] start ['] end over - call PtrToHand drop ( result code )
- "mdef 1 " Mach2 MDEF" call AddResource
- refNum $close-res drop ( result code )
- ;
-
-
-
-
-